﻿// 校验输入的数据是否为空字符串
function isEmpty(str) {
    if ((str == null) || (str.toString().replace(/\s+/g, "") == "")) {
        return true;
    } else {
        return false;
    }
}
function Test1() {
    var oldPassword=$("#old-password").val();
    if (oldPassword!=""){
        var password=$("#password").val();
        if (password!=oldPassword){
            alert("旧密码输入错误");
            return false;
        }
        return true;
    }else{
        alert("旧密码不能为空")
        return false;
    }


}

function Test2() {
    var password1=$("#new-password").val();
    if (password1!=null){
        var password2=$("#confirm-password").val();
        if (password1!=password2){
            alert("两次输入的密码不一致，请重新输入");
           return false;
        }else{
           return true;
        }
    }else{
        alert("新密码不能为空")
    }

}

function updatePwd() {
if (Test1()&&Test2()){
    $.ajax({
        type: "post",
        url: "/common/doupdatePwd.action",
        data: {newpassword: $("#new-password").val()},
        dataType: "json",
        success: function (message) {
            if (message.code == 1) {
                alert("更新成功");
                if (window != top){
                    top.location.href ="/common/doOut.action";
                }
            } else {
                alert("更新失败");
            }
        }
    });
}

}

$("#updatebutton").click(function () {
    var formdateMessage=new FormData($("#updateMessage")[0]);
        $.ajax({
            type:"post",
            data:formdateMessage,
            url:"/common/doupdateMessage.action",
            processData:false,
            contentType:false,
            dataType: "json",
            success:function (message) {
                if (message.code == 1) {
                    alert("更新成功");
                    location.href="/page/common/message.jsp";
                } else {
                    alert("更新失败");
                }
            }
        })
})